﻿using System.Reflection;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;

public class LoadDlllAssets : MonoBehaviour
{
    private string path = Application.streamingAssetsPath;

    public Text text;

    private void Start()
    {
        var ab = AssetBundle.LoadFromFile(path + "/dlltest");

        var dl = ab.LoadAsset<TextAsset>("dll01");

        var refs = Assembly.Load(dl.bytes);

        foreach (var type in refs.GetTypes())
        {
            if (type.Name == "MyClass")
            {
                Debug.Log(type.Name);
                var c = gameObject.AddComponent(type);

                var info = type.GetField("text");
                Debug.Log(info.Name);
                info.SetValue(c , text);

                break;
            }
        }
    }

    public void Load()
    {
        using (var assbundle = UnityWebRequestAssetBundle.GetAssetBundle(""))
        {
            assbundle.Dispose();
        }
    }
}